package com.jsoft.jsofted.sys.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.diboot.core.binding.annotation.BindDict;
import com.diboot.core.binding.annotation.BindField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.IsNotNull;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.persistence.Id;
import java.sql.Timestamp;

@Data
@EqualsAndHashCode(callSuper = false)
@Table("sys_file")
@TableName("sys_file")
@Accessors(chain = true)
public class FileEntity {

    @Column
    @JsonIgnore
    protected Long tenantId;

    @Id
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;

    @Column(length = 128)
    private String name;

    @Column(length = 16)
    private String extName;

    @Column
    private Boolean isImage;

    @TableField
    @JsonIgnore
    private String storagePath;

    @TableField
    private String accessUrl;

    @Column
    @IsNotNull
    protected Timestamp createTime;

    @Column
    @IsNotNull
    protected Timestamp updateTime = new Timestamp(System.currentTimeMillis());

    @Column
    protected Long userId;

    @TableField(exist = false)
    @BindField(entity = UserEntity.class, field = "name", condition = "user_id=id")
    protected String userName;

    @Column(length = 256)
    @IsNotNull
    private String relModule;

    @Column(length = 128)
    @IsNotNull
    private String relType;

    @Column(length = 32)
    @IsNotNull
    private String relField;

    @Column(length = 32)
    private String relId;

    /**
     * 文件来源：
     * 1-上传文件：通过系统界面上传的文件，存放路径通常为 D:/程序目录/upload
     * 2-数据文件：供客户下载的数据模板文件，存放路径通常为 D:/程序目录/data
     * 3-导出文件：导出功能中生成的文件，存放路径通常为 D:/程序目录/export
     */
    @Column(length = 2)
    private String originType;

    @TableField(exist = false)
    @BindDict(type = "FILE_ORIGIN", field = "originType")
    private String originName;

}
